﻿Imports EVOLTA.Promocion.Bl.Bc
Imports EVOLTA.Promocion.Bl.Be

Partial Class rptGerenciales_xTpoInmueble
    Inherits System.Web.UI.Page

    Private xTpoInmueble As List(Of ExTpoInmueble) = Nothing

    Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
        Response.CacheControl = "no-cache"
        Response.AddHeader("Pragma", "no-cache")
        Response.Expires = -1
        '***********************************************************'
        If Not IsPostBack Then
            txtFchInicio.Text = ""
            upFchInicio.Update()
            txtFchFin.Text = ""
            upFchFin.Update()
        End If
    End Sub
    Protected Sub btnBuscar_Click(ByVal sender As Object, ByVal e As System.EventArgs) _
    Handles btnBuscar.Click
        If txtFchInicio.Text.Length > 0 AndAlso txtFchFin.Text.Length > 0 Then
            Dim rptGerencial As New EproformaCabecera
            With rptGerencial
                .idProyecto = Me.Master.idProyecto
                .idEtapa = Me.Master.idEtapa
                .fchInicio = txtFchInicio.Text
                .fchFin = txtFchFin.Text
            End With
            xTpoInmueble = RxTpoInmueble.rptGerenciales_xTpoInmueble(Me.Master.descEmpresa, False, rptGerencial)
            Session("rptGerencial") = xTpoInmueble
            If Not xTpoInmueble Is Nothing Then
                gvwLista.DataSource = xTpoInmueble
                gvwLista.DataBind()
                upGvwLista.Update()
                '    lblTotalIngresosSeparación.Text = String.Format(": {0:###,###,##00.00}", (From prof As EproformaCabecera In proformas _
                '                                                                              Select prof.totalMontoFinal).Sum())
            End If
        End If
    End Sub
    Protected Sub btnLimpiar_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles btnLimpiar.Click
        txtFchInicio.Text = ""
        upFchInicio.Update()
        txtFchFin.Text = ""
        upFchFin.Update()
        gvwLista.DataSource = Nothing
        gvwLista.DataBind()
        upGvwLista.Update()
    End Sub
    Protected Sub btnExportar_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles btnExportar.Click
        xTpoInmueble = Session("rptGerencial")

        If Not xTpoInmueble Is Nothing Then
            Dim fileName As String = "Reporte Gerenciales {0}.xls"
            fileName = String.Format(fileName, DateTime.Now.ToShortDateString())
            Dim Response As HttpResponse = HttpContext.Current.Response
            Response.ContentType = "application/vnd.ms-excel"
            Response.Charset = "UTF-8"
            Response.ContentEncoding = System.Text.Encoding.Default
            Response.AddHeader("Content-Disposition", "attachment; filename=" + fileName)

            Response.Write("Tipo de Inmueble") : Response.Write(vbTab)
            Response.Write("Total Stock") : Response.Write(vbTab)
            Response.Write("Unidades Separadas") : Response.Write(vbTab)
            Response.Write("Unidades Vendidas") : Response.Write(vbTab)
            Response.Write("Monto T. Vendido") : Response.Write(vbTab)
            Response.Write("Monto Cobrado") : Response.Write(vbTab)
            Response.Write("Monto por Cobrar") : Response.Write(vbTab)
            Response.Write("Monto Vencidos") : Response.Write(vbTab)
            Response.Write(vbCrLf)

            Dim value As String
            Dim varIdProforma As Int32 = 0
            For Each xls In xTpoInmueble
                value = xls.descTpoInmueble
                Response.Write(value) : Response.Write(vbTab)

                value = xls.cantidad.ToString("##0.00")
                Response.Write(value) : Response.Write(vbTab)

                value = xls.unidadesSeparadas.ToString("##0.00")
                Response.Write(value) : Response.Write(vbTab)

                value = xls.unidadesVendidas.ToString("##0.00")
                Response.Write(value) : Response.Write(vbTab)

                value = xls.mtoVendido.ToString("#,###,##0.00")
                Response.Write(value) : Response.Write(vbTab)

                value = xls.mtoCobrado.ToString("#,###,##0.00")
                Response.Write(value) : Response.Write(vbTab)

                value = xls.mtoPorCobrar.ToString("#,###,##0.00")
                Response.Write(value) : Response.Write(vbTab)

                value = xls.mtoVencido.ToString("#,###,##0.00")
                Response.Write(value) : Response.Write(vbTab) : Response.Write(vbCrLf)
            Next
            Response.End()
        Else
            Dim jsMensaje As String = Nothing
            jsMensaje = "<script>javascript:alert(' La consulta no pudo ser procesada.  Por favor inténtelo de nuevo.');</script>)"
            Controls.Add(New LiteralControl(jsMensaje))
        End If
    End Sub
    Protected Sub gvwLista_RowDataBound(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.GridViewRowEventArgs) Handles gvwLista.RowDataBound
        If e.Row.RowType = DataControlRowType.DataRow Then
            e.Row.Attributes.Add("OnMouseOver", "Resaltar_On(this);")
            e.Row.Attributes.Add("OnMouseOut", "Resaltar_Off(this);")
            e.Row.Attributes("OnClick") = Page.ClientScript.GetPostBackClientHyperlink(Me.gvwLista, "Select$" + e.Row.RowIndex.ToString)
            e.Row.Style.Add("cursor", "hand")
        End If
    End Sub

End Class
